home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / iw / account.py next >
Encoding:
Python Source  |  2000-03-08  |  9.1 KB  |  284 lines

  1. from gtk import *
  2. from iw import *
  3. from translate import _
  4. import re
  5. import string
  6.  
  7. class AccountWindow (InstallWindow):
  8.  
  9.     userAccountMatch = re.compile("([A-Za-z])([A-Za-z0-9])*")
  10.  
  11.     def __init__ (self, ics):
  12.     InstallWindow.__init__ (self, ics)
  13.  
  14.         self.todo = ics.getToDo ()
  15.         ics.setTitle (_("Account Configuration"))
  16.         ics.readHTML ("accts")
  17.  
  18.     def getNext (self):
  19.     if not self.__dict__.has_key("pw"): return None
  20.  
  21.         self.todo.rootpassword.set (self.pw.get_text ())
  22.     accounts = []
  23.     for n in range(len(self.passwords.keys())):
  24.         accounts.append((self.userList.get_text(n, 0),
  25.                              self.userList.get_text(n, 1),
  26.                              self.passwords[self.userList.get_text(n, 0)]))
  27.     self.todo.setUserList(accounts)
  28.         return None
  29.  
  30.     def rootPasswordsMatch (self, *args):
  31.         pw = self.pw.get_text ()
  32.         confirm = self.confirm.get_text ()
  33.  
  34.         if pw == confirm and len (pw) >= 6:
  35.             self.ics.setNextEnabled (TRUE)
  36.             self.rootStatus.set_text (_("Root password accepted."))
  37.         else:
  38.             if len (pw) < 6:
  39.                 self.rootStatus.set_text (_("Root password is too short."))
  40.             else:
  41.                 self.rootStatus.set_text (_("Root password does not match."))
  42.                 
  43.             self.ics.setNextEnabled (FALSE)
  44.  
  45.     def userOkay(self, *args):
  46.     accountName = self.accountName.get_text()
  47.     password1 = self.userPass1.get_text()
  48.     password2 = self.userPass2.get_text()
  49.  
  50.     if (password1 and password1 == password2 and
  51.         self.userAccountMatch.search(accountName) and
  52.         len(accountName) <= 8) and accountName != "root":
  53.         valid = 1
  54.     else:
  55.         valid = 0
  56.  
  57.     if (self.editingUser != None):
  58.         self.edit.set_sensitive(valid)
  59.         self.add.set_sensitive(0)
  60.     else:
  61.         self.edit.set_sensitive(0)
  62.         self.add.set_sensitive(valid)
  63.  
  64.     def userSelected(self, *args):
  65.     index = self.userList.selection
  66.     if (not index): return
  67.     index = index[0]
  68.     accountName = self.userList.get_text(index, 0)
  69.     fullName = self.userList.get_text(index, 1)
  70.     password = self.passwords[accountName]
  71.  
  72.     self.editingUser = index
  73.     self.accountName.set_text(accountName)
  74.     self.userPass1.set_text(password)
  75.     self.userPass2.set_text(password)
  76.     self.fullName.set_text(fullName)
  77.  
  78.     def addUser(self, widget, *args):
  79.     accountName = self.accountName.get_text()
  80.     password1 = self.userPass1.get_text()
  81.         password2 = self.userPass2.get_text()
  82.     fullName = self.fullName.get_text()
  83.  
  84.         if not (accountName and password1 and (password1 == password2)):
  85.             return
  86.     if accountName == "root":
  87.         return
  88.  
  89.         if self.passwords.has_key (accountName):
  90.             return
  91.  
  92.         if (self.editingUser != None):
  93.         index = self.editingUser
  94.         self.userList.set_text(index, 0, accountName)
  95.         self.userList.set_text(index, 1, fullName)
  96.     else:
  97.         index = self.userList.append((accountName, fullName))
  98.         self.accountName.grab_focus ()
  99.     self.passwords[accountName] = password1
  100.     self.newUser()
  101.  
  102.     def editUser(self, widget, *args):
  103.     index = self.userList.selection
  104.     if (not index): return
  105.     index = index[0]
  106.     accountName = self.userList.get_text(index, 0)
  107.  
  108.         self.editingUser = None
  109.     del self.passwords[accountName]
  110.     self.userList.remove(index)
  111.         self.addUser (None)
  112.  
  113.     def deleteUser(self, *args):
  114.     index = self.userList.selection
  115.     if (not index): return
  116.     index = index[0]
  117.     accountName = self.userList.get_text(index, 0)
  118.  
  119.     del self.passwords[accountName]
  120.     self.userList.remove(index)
  121.     self.newUser()
  122.  
  123.     def newUser(self, *args):
  124.     self.editingUser = None 
  125.     self.accountName.set_text("")
  126.     self.userPass1.set_text("")
  127.     self.userPass2.set_text("")
  128.     self.fullName.set_text("")
  129.  
  130.     def filter(self, widget, text, len, pos):
  131.         # XXX this doesn't check copy/pase
  132.         if len != 1:
  133.             return
  134.         
  135.         # first character case:
  136.         if not widget.get_text ():
  137.             if (text[0] not in string.uppercase and
  138.                 text[0] not in string.lowercase):
  139.                 widget.emit_stop_by_name ("insert-text")
  140.  
  141.         # everything else:
  142.         if (text[0] not in string.uppercase and
  143.             text[0] not in string.lowercase and
  144.             text[0] not in string.digits and
  145.             text[0] not in [ '.', '-', '_' ]):
  146.             widget.emit_stop_by_name ("insert-text")
  147.  
  148.     def getScreen (self):
  149.     self.passwords = {}
  150.     self.editingUser = None
  151.  
  152.         box = GtkVBox ()
  153.         im = self.ics.readPixmap ("root-password.png")
  154.         if im:
  155.             im.render ()
  156.             pix = im.make_pixmap ()
  157.             a = GtkAlignment ()
  158.             a.add (pix)
  159.             a.set (0.0, 0.0, 0.0, 0.0)
  160.             box.pack_start (a, FALSE)
  161.         
  162.         forward = lambda widget, box=box: box.focus (DIR_TAB_FORWARD)
  163.  
  164.         table = GtkTable (2, 2)
  165.         table.set_row_spacings (5)
  166.     table.set_col_spacings (5)
  167.  
  168.         pass1 = GtkLabel (_("Root Password: "))
  169.         pass1.set_alignment (0.0, 0.5)
  170.         table.attach (pass1, 0, 1, 0, 1, FILL, 0, 10)
  171.         pass2 = GtkLabel (_("Confirm: "))
  172.         pass2.set_alignment (0.0, 0.5)
  173.         table.attach (pass2, 0, 1, 1, 2, FILL, 0, 10)
  174.         self.pw = GtkEntry (128)
  175.         self.pw.connect ("activate", forward)
  176.         self.pw.connect ("changed", self.rootPasswordsMatch)
  177.         self.pw.set_visibility (FALSE)
  178.         self.confirm = GtkEntry (128)
  179.         self.confirm.connect ("activate", forward)
  180.         self.confirm.set_visibility (FALSE)
  181.         self.confirm.connect ("changed", self.rootPasswordsMatch)
  182.         table.attach (self.pw,      1, 2, 0, 1, FILL|EXPAND, 5)
  183.         table.attach (self.confirm, 1, 2, 1, 2, FILL|EXPAND, 5)
  184.  
  185.     pw = self.todo.rootpassword.getPure()
  186.     if pw:
  187.         self.pw.set_text(pw)
  188.         self.confirm.set_text(pw)
  189.         
  190.  
  191.         box.pack_start (table, FALSE)
  192.  
  193.         # root password statusbar
  194.         self.rootStatus = GtkLabel ("")
  195.         self.rootPasswordsMatch ()
  196.         box.pack_start (self.rootStatus, FALSE)
  197.  
  198.         box.pack_start (GtkHSeparator (), FALSE, padding=3)
  199.  
  200.         table = GtkTable (2, 3)
  201.         table.set_row_spacings(5)
  202.         table.set_col_spacings(5)
  203.  
  204.         entrytable = GtkTable (4, 4)
  205.         entrytable.set_row_spacings(5)
  206.         entrytable.set_col_spacings(5)
  207.         self.entrytable = entrytable
  208.  
  209.         self.accountName = GtkEntry (8)
  210.         self.accountName.connect ("activate", forward)
  211.         self.accountName.connect ("changed", self.userOkay)
  212.         self.accountName.connect ("insert-text", self.filter)
  213.         
  214.         self.accountName.set_usize (50, -1)
  215.  
  216.         self.fullName = GtkEntry ()
  217.         self.fullName.connect ("activate", self.addUser)
  218.         self.userPass1 = GtkEntry (128)
  219.         self.userPass1.connect ("activate", forward)
  220.         self.userPass1.connect ("changed", self.userOkay)
  221.         self.userPass2 = GtkEntry (128)
  222.         self.userPass2.connect ("activate", forward)
  223.         self.userPass2.connect ("changed", self.userOkay)
  224.         self.userPass1.set_visibility (FALSE)
  225.         self.userPass2.set_visibility (FALSE)
  226.         self.userPass1.set_usize (50, -1)
  227.         self.userPass2.set_usize (50, -1)
  228.  
  229.         label = GtkLabel (_("Account Name") + ": ")
  230.         label.set_alignment (0.0, 0.5)
  231.         entrytable.attach (label,            0, 1, 0, 1, FILL, 0, 10)
  232.         entrytable.attach (self.accountName, 1, 2, 0, 1, FILL|EXPAND)
  233.         label = GtkLabel (_("Password") + ": ")
  234.         label.set_alignment (0.0, 0.5)
  235.         entrytable.attach (label,            0, 1, 1, 2, FILL, 0, 10)               
  236.         entrytable.attach (self.userPass1,   1, 2, 1, 2, FILL|EXPAND)
  237.         label = GtkLabel (_("Password (confirm)") + ": ")
  238.         label.set_alignment (0.0, 0.5)        
  239.         entrytable.attach (label,            2, 3, 1, 2, FILL, 0, 10)               
  240.         entrytable.attach (self.userPass2,   3, 4, 1, 2, FILL|EXPAND)
  241.         label = GtkLabel (_("Full Name") + ": ")
  242.         label.set_alignment (0.0, 0.5)
  243.         entrytable.attach (label,            0, 1, 2, 3, FILL, 0, 10)
  244.         entrytable.attach (self.fullName,    1, 4, 2, 3, FILL|EXPAND)
  245.  
  246.         table.attach (entrytable, 0, 4, 0, 1,
  247.                       xoptions = EXPAND | FILL,
  248.                       yoptions = EXPAND | FILL)
  249.         
  250.         self.add = GtkButton (_("Add"))
  251.     self.add.connect("clicked", self.addUser)
  252.         self.edit = GtkButton (_("Edit"))
  253.     self.edit.connect("clicked", self.editUser)
  254.         delete = GtkButton (_("Delete"))
  255.     delete.connect("clicked", self.deleteUser)
  256.         new = GtkButton (_("New"))
  257.     new.connect("clicked", self.newUser)
  258.  
  259.         bb = GtkHButtonBox ()
  260.         bb.set_border_width (5)
  261.         bb.pack_start (self.add)
  262.         bb.pack_start (self.edit)
  263.         bb.pack_start (delete)
  264.         bb.pack_start (new)
  265.         
  266.         box.pack_start (table, FALSE)
  267.         box.pack_start (bb, FALSE)
  268.         self.userList = GtkCList (2, (_("Account Name"), _("Full Name")))
  269.         for x in range (2):
  270.             self.userList.set_selectable (x, FALSE)
  271.  
  272.     self.userList.connect("select_row", self.userSelected)
  273.         box.pack_start (self.userList, TRUE)
  274.  
  275.         index = 0
  276.     for (user, name, password) in self.todo.getUserList():
  277.         self.userList.append((user, name))
  278.         self.passwords[user] = password
  279.         index = index + 1
  280.  
  281.     self.userOkay()
  282.     box.set_border_width (5)
  283.         return box
  284.